home *** CD-ROM | disk | FTP | other *** search
- ;******************************************************************************
- ;This is the task which executes at privilege level 0 in protected mode. Its
- ;job is to start up the V86 Virtual Machine.
- ;******************************************************************************
-
- TASK1 SEGMENT PARA USE32 'CODE'
- ASSUME CS:TASK1, DS:TASK1, SS:TASK1
-
- ;The following are the selectors defined in protected mode
- Null EQU 0H
- BIOS_SEL EQU 08H+RPL0 ;bios data ram segment (0:0) selector
- TSS_1_SEL EQU 10H+RPL0 ;selector for TSS for task 1
- CODE_1_SEL EQU 18H+RPL0 ;task 1 code segment selector
- DATA_1_SEL EQU 20H+RPL0 ;task 1 data segment selector
- TSS_2_SEL EQU 28H+RPL3 ;selector for TSS for task 2
-
- SEG_FAULT DW 0 ;segment to remap
- NEW_21H DD 0 ;new INT 21H handler vector
-
- ;This routine is responsible for getting the V86 machine up and running.
- V86_LOADER:
- mov ax,DATA_1_SEL ;now set up segments
- mov ds,ax ;for protected mode
- mov es,ax
- mov fs,ax
- mov gs,ax
- mov ss,ax ;set up stack
- mov esp,OFFSET TASK1_STACK + STACK_SIZE
- xor eax,eax
- lldt ax ;make sure ldt register is 0
- call SETUP_PAGE_TABLES ;setup paging
- mov ax,TSS_1_SEL ;init task register
- ltr ax
- mov eax,118000H ;set up page directory @
- mov cr3,eax
- mov eax,cr0 ;turn paging on
- or eax,80000000H
- mov cr0,eax
- jmp FWORD PTR [TASK_GATE_2] ;go to V86 mode
-
-
- ;This routine sets up the page table for protected paging. It expects es to
- ;point to the page table segment.
- SETUP_PAGE_TABLES:
- ;First, build page directory at 118000H, page table at 119000H
- mov eax,119007H ;set up page dir
- mov edi,8000H ;location of page directory
- stosd ;first entry points to a table
- mov eax,0
- mov ecx,1023
- rep stosd ;the rest are empty
-
- ;Now build standard page table at 119000H
- mov eax,7 ;all pages accessible
- mov ebx,4096 ;linear mem = physical mem
- mov ecx,1024
- SPLP1: stosd
- add eax,ebx
- loop SPLP1
-
- ;Now build another page directory at 11A000H, pg table at 11B000H
- mov eax,11B007H ;set up page dir
- stosd ;first entry points to a table
- mov eax,0
- mov ecx,1023
- rep stosd ;the rest are empty
-
- ;And build the page table for stealthed operation at 11B000H
- xor edx,edx
- mov dx,[SEG_FAULT]
- shl edx,4 ;ebp=start @ to stealth
- add edx,7
- mov eax,7 ;now do page table
- mov ebx,4096
- mov ecx,1024
- SPLP2: cmp eax,edx ;set pages below 1st to
- je SP1 ;stealth up
- stosd ;with linear=physical
- add eax,ebx
- loop SPLP2
-
- SP1: sub cx,PAGES
- push ecx ;save count for later
- xor ecx,ecx
- mov cx,PAGES ;ecx=pages to fault
- mov eax,11C007H ;location of 1st stealthed pg
- SPLP3: stosd ;set up stealthed pages
- add eax,ebx
- add edx,ebx
- loop SPLP3
-
- pop ecx ;now finish up
- mov eax,edx
- SPLP4: stosd
- add eax,ebx
- loop SPLP4
- ret
-
- ;Include interrupt handlers for protected mode here.
- INCLUDE GPFAULT.ASM ;general protection fault handler
- INCLUDE HWHNDLR.ASM ;hardware interrupt handlers
- INCLUDE PMVIDEO.ASM ;protected mode video handler
- ;INCLUDE PGFAULT.ASM ;page fault routine
- INCLUDE NOTIMP.ASM ;handler for anything not implemented
-
- INCLUDE TABLES.ASM ;include GDT, IDT and TSS tables
-
- SEG_END:
-
- TASK1_STACK DB STACK_SIZE DUP (?) ;Stack for this task
-
- TASK2_STACK0 DB STACK_SIZE DUP (?)
- TASK2_STACK1: ;never used
- TASK2_STACK2:
-
- END_TASK1: ;end of this segment
-
- TASK1 ENDS
-